<?php
class category_model extends CI_Model{
	
	function __construct(){
		parent::__construct();
		$this->load->database();
	}
	
	
	
	/**
	 * Obtener lista de banners
	 */
	public function get($params){
		$type = 'id_categoria = id_categoria';
		if(isset($params['genre'])){
			$type .= ($type!=''?' AND ': '').'id_categoria = '.$params['genre'];
		}
		
		$res = $this->db
			->select('
				id_categoria AS id,
				nombre AS name')
			->from('categorias')
			->where($type)
			->order_by('nombre', 'ASC')
		->get();
		
		return array('categories' => $res->result_array());
	}


	
	private function exist($table, $sql, $return_res=false){
		$res = $this->db->get_where($table, $sql);
		if($res->num_rows() > 0){
			if($return_res)
				return $res->row();
			return TRUE;
		}
		return FALSE;
	}
}